<!DOCTYPE html>
<html>
<head>
    <title>检测医院管理</title>
    {% include 'admin/common/header.html' %}
</head>
<body>
<form class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">

                <div class="layui-form-item">
                    <label class="layui-form-label">所属医院</label>
                    <div class="layui-input-block">
                        <select name="hospital_no" lay-verify="required" lay-search>
                            <option value="">请选择</option>
                            {% for hospital in hospital_list %}
                                <option value="{{ hospital.hospital_no }}" {% if hospital.hospital_no == hospital_no %}selected{% endif %}>{{ hospital.name }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">检测设备</label>
                    <div class="layui-input-block">
                        <select name="device_no" lay-verify="required" lay-search>
                            <option value="">请选择</option>
                            {% for device in device_list %}
                                <option value="{{ device.device_no }}" {% if device.device_no == device_no %}selected{% endif %}>{{ device.name }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">u6</label>
                    <div class="layui-input-block">
                        <input type="text" value="" readonly name="u6" lay-verify="required" autocomplete="off" class="layui-input" style="display: inline-block;width: 70%;">
                         <button type="button" class="layui-btn layui-btn-normal" id="up-u6" style="padding: 0 10px;">选择文件</button>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">mir</label>
                    <div class="layui-input-block">
                        <input type="text" value="" readonly name="mir" lay-verify="required" autocomplete="off" class="layui-input" style="display: inline-block;width: 70%;">
                         <button type="button" class="layui-btn layui-btn-normal" id="up-mir" style="padding: 0 10px;">选择文件</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="hospital-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{% include 'admin/common/footer.html' %}
<script>
  layui.use(['form', 'jquery', 'upload'], function () {
    let form = layui.form;
    let $ = layui.jquery;
    let upload = layui.upload;
    upload.render({
        elem: '#up-u6'
        , url: "{{ url_for('adminFile.upload_txt') }}"
        , accept:'file'
        , exts: 'txt'
        , size: 4096
        , done: function (res) {
            if (res.success) {
                layer.msg(res.msg, {icon: 1, time: 500}, function () {
                    $('[name="u6"]').val(res.data.src);
                });
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }
    });
    upload.render({
        elem: '#up-mir'
        , url: "{{ url_for('adminFile.upload_txt') }}"
        , accept:'file'
        , exts: 'txt'
        , size: 4096
        , done: function (res) {
            if (res.success) {
                layer.msg(res.msg, {icon: 1, time: 500}, function () {
                    $('[name="mir"]').val(res.data.src);
                });
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }
    });
    form.on('submit(hospital-save)', function (data) {
      let loading = layer.load()
      $.ajax({
        url: '/admin/record/save',
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'post',
        success: function (result) {
          layer.close(loading)
          if (result.success) {
            layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
              parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
              parent.layui.table.reload('record-table')
            })
          } else {
            layer.msg(result.msg, { icon: 2, time: 1000 })
          }
        }
      })
      return false
    })
  })
</script>
</body>
</html>